package org.lizar.log;

import java.util.Calendar;

import org.lizar.Web;


public class Console implements Log {

	public static final String LOG_TYPE="[Console debug] ";
	
	private String _t;
	
	public Console(Class t){
		_t=t.getName();
	}
	
	@Override
	public void debug(String message) {
		if(Web.debug){
			StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
			msg.append(LOG_TYPE).append(_t).append(" ").append(message);
			System.out.println(msg);
		}
		
	}

	@Override
	public void debug(String message, Throwable t) {
		// TODO Auto-generated method stub
		if(Web.debug){
			StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
			msg.append(LOG_TYPE).append(_t).append(" ").append(message);
			System.out.println(msg);
			t.printStackTrace();
		}
		
	}

	@Override
	public void error(String message) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ").append(message);
		System.err.println(msg);
	}

	@Override
	public void error(String message, Throwable t) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ").append(message);
		System.err.println(msg);
		t.printStackTrace();
	}

	@Override
	public void info(String message) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ").append(message);
		System.out.println(msg);
	}

	@Override
	public void info(String message, Throwable t) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ").append(message);
		System.out.println(msg);
		t.printStackTrace();
	}

	@Override
	public void warn(String message) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ").append(message);
		System.err.println(msg);
	}

	@Override
	public void warn(String message, Throwable t) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ").append(message);
		System.err.println(msg);
		t.printStackTrace();
	}

	public static void main(String[] args){
		String[] arr="sdf.".split("\\.");
		System.out.println(arr.length);
		System.out.println(arr[0]);
		System.out.println(arr[1]);
	}

	@Override
	public void debug(Throwable t) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ");
		System.out.println(msg);
		t.printStackTrace();
	}

	@Override
	public void error(Throwable t) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ");
		System.err.println(msg);
		t.printStackTrace();
	}

	@Override
	public void info(Object obj) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ");
		System.out.println(msg);
		System.out.println(obj);
	}

	@Override
	public void info(Throwable t) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ");
		System.out.println(msg);
		t.printStackTrace();
	}

	@Override
	public void warn(Throwable t) {
		StringBuilder msg=new StringBuilder(Calendar.getInstance().getTime().toString());
		msg.append(LOG_TYPE).append(_t).append(" ");
		System.err.println(msg);
		t.printStackTrace();
	}

}
